package com.twd.websocket;


import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.stream.ChunkedWriteHandler;

/**
 * @author Chris Chan
 * Create on 2021/4/18 15:10
 * Use for:
 * Explain:
 */
public class WebSocketServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ch.pipeline()
                .addLast("HttpServerCodec", new HttpServerCodec())
                .addLast("ChunkedWriteHandler", new ChunkedWriteHandler())
                .addLast("HttpObjectAggregator", new HttpObjectAggregator(8192))
                .addLast("WebsocketConnectHandler", new WebsocketConnectHandler("/chat"))
                .addLast("WebSocketServerProtocolHandler", new WebSocketServerProtocolHandler("/chat"))
                .addLast("WebSocketServerHandler", new WebSocketServerHandler());

    }
}